$(document)
		.ready(
				function() {
					$
							.ajax({
								type : "post",
								url : "myUser",
								async : true,
								dataType : 'json',
								success : function(data) {

									var name = data.userVo.name;// 名字
									var location = data.userVo.location;// 地址
									var phoneNum = data.userVo.phoneNum;// 联系电话
									var synopsis = data.userVo.synopsis;// 个人简介/个性签名
									var sex = data.userVo.sex;// 性别

									var fans_length = data.userVo.fans.length;// 粉丝
									var follows_length = data.userVo.follows.length;// 关注
									var articles_length = data.userVo.articles.length;// 发布
									var discusses_length = data.userVo.discusses.length;// 发布多个评论
									var joinArticles_length = data.userVo.joinArticles.length;// 参加多个活动（文章）
									var dongtai_length = articles_length
											+ discusses_length
											+ joinArticles_length;// 动态

									var face = data.userVo.myFile.name;// 头像文件名
									var servicePath = 'myAssets//img//face//';

									var articlePath = 'myAssets//img//article//';// 文章文件路径
									var facePath = 'myAssets//img//face//';// 头像文件路径

									console.log(data)
									console.log(name)
									console.log(location)
									console.log(phoneNum)
									console.log(synopsis)
									console.log(sex)
									console.log(fans_length)
									console.log(dongtai_length)
									$("#heUser-name").html(name);
									$("#name").html(name);
									$("#location").html(location);
									$("#synopsis").html(synopsis);

									// $("#fans_length").html(fans_length);//粉丝
									// $("#follows_length").html(follows_length);//关注
									// $("#dongtai_length").html(dongtai_length);//动态
									// $("#articles_length").html(articles_length);//发布

									$('#faceimg').attr('src',
											servicePath + face);// 头像
									var followsButHTML = '<li><a class="link_share_button" href="javascript:;" id="but-Addfollows"><i class="iconfont share_ico_link">&#xe889;</i>关注</a></li>';
									var fans_list = data.userVo.fans;
									if(data.userid=='-1'){		
										var followsButHTML = '<li><a class="link_share_button" href="javascript:;" ><i class="iconfont share_ico_link">&#xe889;</i>无法关注</a></li>';	
									}else{
										for (var i = 0; i < fans_list.length; i++) {
											if (fans_list[i].id == data.userid) {
												followsButHTML = '<li><a class="link_share_button" href="javascript:; id="but-deletefollows""><i class="iconfont share_ico_link">&#xe888;</i>取消关注</a></li>';
											}
										}
									}
									
									
									// 添加关注 和信息按钮
									$('#fans-follows').append(followsButHTML);
									$('#fans-follows')
											.append(
													'<li><a class="link_share_button" href="###"><i class="iconfont share_ico_wx">&#xe70b;</i>信息(未开放)</a></li>');
									$('#whole_list')
											.html(
													' <span><a href="userDongtai?id='
															+ data.userVo.id
															+ '">'
															+ dongtai_length
															+ '</a><i>动态</i></span><span><a href="userList?id='
															+ data.userVo.id
															+ '&resultType=userFollows" >'
															+ follows_length
															+ '</a><i>关注</i></span> <span><a href="userList?id='
															+ data.userVo.id
															+ '&resultType=userFans" id="a_fans_length">'
															+ fans_length
															+ '</a><i>粉丝</i></span> <span><a href="userArticle?id='
															+ data.userVo.id
															+ '" >'
															+ articles_length
															+ '</a><i>发布</i></span>');

									var list = data.userVo.articles;
									if (list.length != 0) {
										for (var i = 0; i < list.length; i++) {
											var id = list[i].id;
											var type = list[i].type;
											var title = list[i].title;// 标题
											var content = list[i].content;// 内容
											var date = list[i].date;// 发布时间
						  					var startDate = list[i].startDate;// 活动开始时间
											var endDate = list[i].endDate;// 活动结束时间
											var address = list[i].address;// 地址
											var joinUserNum = list[i].joinUserNum;// 参加人数int
											var goodArticle = list[i].goodArticle;// 点赞user
											if (type == 'yule'
													|| type == 'xueshu'
													|| type == 'jingsai'
													|| type == 'shetuan'
													|| type == 'qita') {

												if (type == 'yule') {
													type = '&#xe75a;'
												}
												if (type == 'xueshu') {
													type = '&#xe7f3;'
												}
												if (type == 'jingsai') {
													type = '&#xea65;'
												}
												if (type == 'shetuan') {
													type = '&#xe7fc;'
												}
												if (type == 'qita') {
													type = '&#xe7c8;'
												}

												var reg = new RegExp("-", "g");
												endDate1 = endDate.replace(reg,
														'');// 活动结束时间
												startDate1 = startDate.replace(
														reg, '');// 开始时间
												newdate1 = data.newdate
														.replace(reg, '');// 当前时间
												var articleboff;
												// 活动开始时间
												if (endDate1 > newdate1) {
													articleboff = '<span>报名中</span>';

												} else {
													articleboff = '<span class="hd_tag_js">已截止</span>';

												}
												if (endDate1 >= newdate1
														&& startDate1 <= newdate1) {
													articleboff = '<span class="hd_tag_jh">进行中</span>';

												}

												var newstartDate = startDate
														.substring(10, 5)
														.replace("-", "月")
														+ '日';// 报名开放日期
												var newendDate = endDate
														.substring(10, 5)
														.replace("-", "月")
														+ '日';// 报名结束日期

												var newstartDateSSS = startDate
														.slice(11);// 报名开放时间
												// 12:30
												var newendDateSSS = endDate
														.slice(11);// 报名结束时间
												// 20:30

												var playDate = newendDate + ' '
														+ newstartDateSSS + '-'
														+ newendDateSSS;
												var joinUserhtml = '';
												var joinUser = list[i].joinUser;
												// for(var j = 0; j <
												// joinUser.length; j++){
												// if(joinUser[j].id==data.userid){
												// joinUserhtml='<div
												// class="pet_topci_video"
												// style="background-color:
												// limegreen;"><span>已参加</span></div>';
												// }
												// }

												$("#articel-List")
														.append(
																'<li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-right pet_hd_list">'
																		+ joinUserhtml
																		+ ' <a href="articleOne?id='
																		+ id
																		+ '" class="pet_hd_block"> <div class="pet_hd_block_title">'
																		+ title
																		+ '</div> <div class="pet_hd_block_map"> <i class="iconfont">'
																		+ type
																		+ '</i>'
																		+ address
																		+ '</div>	<div class="pet_hd_block_tag">'
																		+ articleboff
																		+ '  '
																		+ playDate
																		+ '</div>	</a>	</li>');
											}
											if (type == 'jiaoxue'
													|| type == 'fenxiang'
													|| type == 'tiwen'
													|| type == 'quwen') {
												if (list[i].myFiles.length == 0) {
													$("#articel-List")
															.append(
																	'  <li class="am-g am-list-item-desced pet_list_one_block" ><div class=" am-list-main"><h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
																			+ id
																			+ '" class="">'
																			+ title
																			+ '</a></h3><div class="am-list-item-text pet_list_two_text">'
																			+ content
																			+ '</div></div></li>');
												}
												if (list[i].myFiles.length == 1
														|| list[i].myFiles.length == 2) {
													$("#articel-List")
															.append(
																	' <li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-right pet_list_one_block"> <div class=" am-u-sm-8 am-list-main pet_list_one_nr">													            <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
																			+ id
																			+ '" class="">'
																			+ title
																			+ '</a></h3>													            <div class="am-list-item-text pet_list_one_text">'
																			+ content
																			+ '</div>										        </div>					          <div class="am-u-sm-4 am-list-thumb">  <a href="articleStudyOne?id='
																			+ id
																			+ '" class=""> <img src="'
																			+ articlePath
																			+ list[i].myFiles[0].name
																			+ '" class="pet_list_one_img" alt=""/></a>  </div> </li>');
												}
												if (list[i].myFiles.length >= 3) {
													$("#articel-List")
															.append(
																	'            <li class="am-g am-list-item-desced pet_list_one_block"> <div class=" am-list-main">   <h3 class="am-list-item-hd pet_list_one_bt"><a href="articleStudyOne?id='
																			+ id
																			+ '" class="">'
																			+ title
																			+ '</a></h3> <ul data-am-widget="gallery" class="am-gallery am-avg-sm-3  am-avg-md-3 am-avg-lg-3 am-gallery-default pet_list_one_list" >  <li> <div class="am-gallery-item">    <a href="articleStudyOne?id='
																			+ id
																			+ '" class="">      <img src="'
																			+ articlePath
																			+ list[i].myFiles[0].name
																			+ '"  alt=""/>    </a>     </div>     </li>    <li>   <div class="am-gallery-item">   <a href="articleStudyOne?id='
																			+ id
																			+ '" class="">   <img src="'
																			+ articlePath
																			+ list[i].myFiles[1].name
																			+ '"  alt=""/>  </a> </div>	      </li>    <li>    <div class="am-gallery-item">  <a href="articleStudyOne?id='
																			+ id
																			+ '" class="">       <img src="'
																			+ articlePath
																			+ list[i].myFiles[2].name
																			+ '"  alt=""/>    </a>   </div>   </li>	  </ul>         <div class="am-list-item-text pet_list_two_text">'
																			+ content
																			+ '</div>		        </div>   </li>');
												}

											}
										}
										$(document)
												.ready(
														function() {
															// 动态计算新闻列表文字样式
															auto_resize();
															$(window)
																	.resize(
																			function() {
																				auto_resize();
																			});
															$(
																	'.am-list-thumb img')
																	.load(
																			function() {
																				auto_resize();
																			});
															$(
																	'.pet_article_like li:last-child')
																	.css(
																			'border',
																			'none');
															function auto_resize() {
																$(
																		'.pet_list_one_nr')
																		.height(
																				$(
																						'.pet_list_one_img')
																						.height());
																// alert($('.pet_list_one_nr').height());
															}
															$(
																	'.pet_article_user')
																	.on(
																			'click',
																			function() {
																				if ($(
																						'.pet_article_user_info_tab')
																						.hasClass(
																								'pet_article_user_info_tab_show')) {
																					$(
																							'.pet_article_user_info_tab')
																							.removeClass(
																									'pet_article_user_info_tab_show')
																							.addClass(
																									'pet_article_user_info_tab_cloes');
																				} else {
																					$(
																							'.pet_article_user_info_tab')
																							.removeClass(
																									'pet_article_user_info_tab_cloes')
																							.addClass(
																									'pet_article_user_info_tab_show');
																				}
																			});

															$(
																	'.pet_head_gd_ico')
																	.on(
																			'click',
																			function() {
																				$(
																						'.pet_more_list')
																						.addClass(
																								'pet_more_list_show');
																			});
															$('.pet_more_close')
																	.on(
																			'click',
																			function() {
																				$(
																						'.pet_more_list')
																						.removeClass(
																								'pet_more_list_show');
																			});
														});
									}

								},
								error : function() {
								}
							});
				})

// 获取url中的参数
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); // 匹配目标参数
	var result = window.location.search.substr(1).match(reg); // 对querystring匹配目标参数
	if (result != null) {
		return decodeURIComponent(result[2]);
	} else {
		return null;
	}
}
$('body').on('click', '#but-Addfollows', function () {  
	console.log('guodayang 测试')
	var id = getQueryString('id');
	$.ajax({
		type : "post",
		async : true,
		url : "addFollows",
		data : {
			'id' : id,
		},
		dataType : 'json',
		success : function(data) {
			$('#fans-follows').html('<li><a class="link_share_button" href="javascript:; id="but-deletefollows""><i class="iconfont share_ico_link">&#xe888;</i>取消关注</a></li><li><a class="link_share_button" href="###"><i class="iconfont share_ico_wx">&#xe70b;</i>信息(未开放)</a></li>');
			var fans1 = document.getElementById('a_fans_length').innerHTML;
			var fans2 = Number(fans1)+1;
			$('#a_fans_length').html(fans2);
		},
		error : function() {
		}
	});
});  				
